import { LoggerService } from '@nestjs/common';

export const loggerConfig = {
  development: {
    level: 'debug',
    prettyPrint: true,
    colorize: true,
    timestamp: true,
    showStack: true,
  },
  production: {
    level: 'warn',
    prettyPrint: false,
    colorize: false,
    timestamp: true,
    showStack: false,
  },
  test: {
    level: 'error',
    prettyPrint: false,
    colorize: false,
    timestamp: false,
    showStack: false,
  },
};

export const getLoggerConfig = (): any => {
  const env = process.env.NODE_ENV || 'development';
  return loggerConfig[env] || loggerConfig.development;
};

// 自定义日志服务
export class CustomLoggerService implements LoggerService {
  private context?: string;

  constructor(context?: string) {
    this.context = context;
  }

  log(message: any, context?: string) {
    const timestamp = new Date().toISOString();
    const ctx = context || this.context || 'Application';
    console.log(`[${timestamp}] [LOG] [${ctx}] ${message}`);
  }

  error(message: any, trace?: string, context?: string) {
    const timestamp = new Date().toISOString();
    const ctx = context || this.context || 'Application';
    console.error(`[${timestamp}] [ERROR] [${ctx}] ${message}`);
    if (trace) {
      console.error(`[${timestamp}] [ERROR] [${ctx}] Stack Trace: ${trace}`);
    }
  }

  warn(message: any, context?: string) {
    const timestamp = new Date().toISOString();
    const ctx = context || this.context || 'Application';
    console.warn(`[${timestamp}] [WARN] [${ctx}] ${message}`);
  }

  debug(message: any, context?: string) {
    const timestamp = new Date().toISOString();
    const ctx = context || this.context || 'Application';
    console.debug(`[${timestamp}] [DEBUG] [${ctx}] ${message}`);
  }

  verbose(message: any, context?: string) {
    const timestamp = new Date().toISOString();
    const ctx = context || this.context || 'Application';
    console.log(`[${timestamp}] [VERBOSE] [${ctx}] ${message}`);
  }
} 